﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DevExpress.XtraEditors.Repository;
using DevExpress.XtraEditors;

namespace Ahi.Controller
{
    public static class RepositoryItemLookUpEditExtensions
    {
        public static void SetEnumList<T>(this RepositoryItemLookUpEdit editor, string nullText = "Seçiniz")
            where T : struct,IComparable
        {
            editor.DisplayMember = "Value";
            editor.ValueMember = "Key";
            editor.NullText = nullText;
            editor.DataSource = EnumListeController<T>.Instance.List;

            editor.Columns.Clear();
            editor.Columns.AddRange(new DevExpress.XtraEditors.Controls.LookUpColumnInfo[] {
            new DevExpress.XtraEditors.Controls.LookUpColumnInfo(editor.ValueMember, "", 5,
                DevExpress.Utils.FormatType.None, "", false,
                DevExpress.Utils.HorzAlignment.Default,
                DevExpress.Data.ColumnSortOrder.None),
            new DevExpress.XtraEditors.Controls.LookUpColumnInfo(editor.DisplayMember)});

            editor.ShowHeader = false;
            editor.ShowFooter = false;
        }

        public static void SetEnumList<T>(this LookUpEdit editor, string nullText = "Seçiniz")
            where T : struct,IComparable
        {
            editor.Properties.DisplayMember = "Value";
            editor.Properties.ValueMember = "Key";
            editor.Properties.NullText = nullText;
            editor.Properties.DataSource = EnumListeController<T>.Instance.List;

            editor.Properties.Columns.Clear();
            editor.Properties.Columns.AddRange(new DevExpress.XtraEditors.Controls.LookUpColumnInfo[] {
            new DevExpress.XtraEditors.Controls.LookUpColumnInfo(editor.Properties.ValueMember, "", 5,
                DevExpress.Utils.FormatType.None, "", false,
                DevExpress.Utils.HorzAlignment.Default,
                DevExpress.Data.ColumnSortOrder.None),
            new DevExpress.XtraEditors.Controls.LookUpColumnInfo(editor.Properties.DisplayMember)});

            editor.Properties.ShowHeader = false;
            editor.Properties.ShowFooter = false;
        }

        public static void SetDataSource(this RepositoryItemLookUpEdit editor, string displayMember, string valueMember, object dataSource, string nullText = "Seçiniz")
        {
            editor.DisplayMember = displayMember;
            editor.ValueMember = valueMember;
            editor.NullText = nullText;
            editor.DataSource = dataSource;

            editor.Columns.Clear();
            editor.Columns.AddRange(new DevExpress.XtraEditors.Controls.LookUpColumnInfo[] {
            new DevExpress.XtraEditors.Controls.LookUpColumnInfo(editor.ValueMember, "", 5,
                DevExpress.Utils.FormatType.None, "", false,
                DevExpress.Utils.HorzAlignment.Default,
                DevExpress.Data.ColumnSortOrder.None),
            new DevExpress.XtraEditors.Controls.LookUpColumnInfo(editor.DisplayMember)});

            editor.ShowHeader = false;
            editor.ShowFooter = false;
        }

        public static void SetDataSource(this LookUpEdit editor, string displayMember, string valueMember, object dataSource, string nullText = "Seçiniz")
        {
            editor.Properties.DisplayMember = displayMember;
            editor.Properties.ValueMember = valueMember;
            editor.Properties.NullText = nullText;
            editor.Properties.DataSource = dataSource;

            editor.Properties.Columns.Clear();
            editor.Properties.Columns.AddRange(new DevExpress.XtraEditors.Controls.LookUpColumnInfo[] {
            new DevExpress.XtraEditors.Controls.LookUpColumnInfo(editor.Properties.ValueMember, "", 5,
                DevExpress.Utils.FormatType.None, "", false,
                DevExpress.Utils.HorzAlignment.Default,
                DevExpress.Data.ColumnSortOrder.None),
            new DevExpress.XtraEditors.Controls.LookUpColumnInfo(editor.Properties.DisplayMember)});

            editor.Properties.ShowHeader = false;
            editor.Properties.ShowFooter = false;
        }

        public static void RefreshDataSource(this LookUpEdit editor)
        {
        }
    }
}
